package com.itheima.socket.tcp.demo09;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端代码实现
 */
public class ClientDemo01 {

    public static void main(String[] args) throws Exception {

        // 1. 创建Socket对象
        Socket socket = new Socket(InetAddress.getByName("169.254.106.206") , 8080) ;

        // 2. 获取输出流对象(获取到的是字节输出流)
        OutputStream outputStream = socket.getOutputStream();

        // 3. 把字节输出流转换成字符输出流 ， 并且使用高效的流对象进行封装
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream)) ;

        // 4. 客户端读取文本文件数据发送到服务端
        // 创建一个高效的字符输入流对象
        BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\a.txt")) ;
        String line = null ;
        while((line = bufferedReader.readLine()) != null) {
            bufferedWriter.write(line);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }

        // 资源释放
        bufferedReader.close();
        socket.close();
    }

}
